/**
* Created by ren on 2017/1/4.
*/
<template>
  <div class='asset'>
    <div class="mezc">
      <div class="left">
        <chart :options="pie" class="chart-style"></chart>
        <div class="chart-text">
          <div>总资产（元+克）</div>
          <div>现金{{(assetsData.cash/100).toFixed(2)}}</div>
          <div>黄金{{(assetsData.glod/1000).toFixed(1)}}g</div>
        </div>
        <div class="end-text">
          共约 <span style="font-size: 18px">{{(assetsData.sumGlod/1000).toFixed(2)}}</span>g黄金
        </div>
      </div>
      <img src="../../assets/line5.png" style="margin-top: 50px;float: left;margin-right: 49px">
      <div class="right">
        <div>
          <label>预期收益</label> <span>¥{{(assetsData.earnings/100).toFixed(2)}}</span>
        </div>
        <img src="../../assets/line6.png">
        <div style="margin-bottom: 20px">
          <label>已购黄金</label> <span>{{(assetsData.buyGold/1000).toFixed(1)}}g</span>
        </div>
        <div style="margin-bottom: 20px">
          <label>金生金</label> <span>{{(assetsData.kinSonGoldWeight/1000).toFixed(1)}}g</span>
        </div>
        <div>
          <label>黄金定投</label> <span>{{(assetsData.regularPutinWeight/1000).toFixed(1)}}g</span>
        </div>
      </div>
    </div>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import ECharts from 'vue-echarts/dist/vue-echarts'
  import API from '../../api'
  import Notify from '../Notify'
  export default {
    name: 'asset',
    components: {
      'chart': ECharts,
      Notify
    },
    props: ['_parentThis'],
    data: function () {
      return {
        notifyStatus: 2,
        assetsData: '',
        pie: {
          tooltip: {
            show: false
          },
          legend: {
            /*
             TODO : Change show key
             */
            show: true,
            orient: 'vertical',
            x: 'left',
            data: ['data-one', 'data-two']
          },
          color: [
            '#ffb692',
            '#f48315'
          ],
          series: [
            {
              type: 'pie',
              radius: ['50%', '60%'],
              avoidLabelOverlap: false,
              labelLine: {
                normal: {
                  show: false
                }
              },
              hoverAnimation: false,
              data: [
                {value: 100},
                {value: 800}
              ]
            }
          ]
        }
      }
    },
    methods: {
      findMyAssets: function () {
        if (!this.$cookie.get('id')) {
          this.$router.push({'name': 'login'})
        }
        this.$http.post(API.findMyAssets, {
          id: this.$cookie.get('id')
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.assetsData = result.object
            this._parentThis.jinshengjinData = result.object.kinsonGoldVo
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      }
    },
    mounted: function () {
      this.findMyAssets()
    }
  }
</script>
